package com.ki.glasscase.svc.services.impl;

import com.ki.glasscase.svc.dao.TagDAO;
import com.ki.glasscase.svc.entity.Product;
import com.ki.glasscase.svc.entity.Tag;
import com.ki.glasscase.svc.services.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Khacheresyants.l on 2/27/14.
 */
@Service
public class ImplTagService implements TagService {

    @Autowired
    public TagDAO tagDAO;

    @Override
    public Long create(Tag tag) {
        return tagDAO.create(tag);
    }

    @Override
    public Long update(Tag tag) {
        return tagDAO.update(tag);
    }

    @Override
    public Tag getTagByName(String name) {
        return tagDAO.getTagByName(name);
    }

    @Override
    public Tag getTagById(int id) {
        return tagDAO.getTagById(id);
    }

    @Override
    public List<Tag> getAll(int limit) {
        return tagDAO.getAll(limit);
    }

    @Override
    public Map<String, List<Tag>> getAllTagByProduct(List<Product> products) {
            Map<String, List<Tag>> map = new HashMap<String, List<Tag>>();
            for(Product product: products){
               map.put(product.getName(),tagDAO.getTagByProductId(product.getId()));
            }
        return map ;
    }
}
